using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class ResultDisplay : MonoBehaviour
{
    public List<GameObject> PanelResultList;

    public Button ButtonRetry;
    public Button ButtonQuit;

    // Start is called before the first frame update
    void Start()
    {
        // Bind Events
        {
            ButtonRetry.onClick.AddListener(delegate ()
            {
                OnButtonRetryClicked();
            });

            ButtonQuit.onClick.AddListener(delegate ()
            {
                OnButtonQuitClicked();
            });
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            OnButtonQuitClicked();
            return;
        }
        else if (Input.GetKeyDown(KeyCode.U) || Input.GetKeyDown(KeyCode.I)
        || Input.GetKeyDown(KeyCode.J)
        || Input.GetKeyDown(KeyCode.K)
        || Input.GetKeyDown(KeyCode.Keypad2)
        || Input.GetKeyDown(KeyCode.Keypad5)
        || Input.GetKeyDown(KeyCode.Keypad3)
        || Input.GetKeyDown(KeyCode.Keypad6))
        {
            OnButtonRetryClicked();
        }
    }

    public void OnDisplayResult(int InWinnerIdx)
    {
        if (0 == InWinnerIdx)
            InWinnerIdx = 2;

        AudioManager.Instance.PlaySE("SE_05_Finish");
        switch (InWinnerIdx)
        {
            case 1:
                AudioManager.Instance.PlaySE("Vo_01_Win");
                break;
            case 2:
                AudioManager.Instance.PlaySE("Vo_02_Win");
                break;
            default:
                break;
        }
        for (int i = 0; i < PanelResultList.Count; i++)
        {
            PanelResultList[i].SetActive(i == InWinnerIdx);
        }
    }

    public void OnButtonRetryClicked()
    {
        FXManager.Instance.ShowUIFX(4);
    }

    public void OnButtonQuitClicked()
    {
        SceneManager.LoadScene("Entry");
        AudioManager.Instance.PlayerBGM1();
    }
}
